package com.ruoyi.kuaipai.controller;

import java.util.List;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.kuaipai.domain.KpPointDetails;
import com.ruoyi.kuaipai.service.IKpPointDetailsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 点数明细Controller
 *
 * @author 金龙
 * @date 2025-04-26
 */
@RestController
@RequestMapping("/kuaipai/point")
public class KpPointDetailsController extends BaseController {
    @Autowired
    private IKpPointDetailsService kpPointDetailsService;

    /**
     * 查询点数明细列表
     */
    @PreAuthorize("@ss.hasPermi('kuaipai:point:list')")
    @GetMapping("/list")
    public TableDataInfo list(KpPointDetails kpPointDetails) {
        startPage();
        List<KpPointDetails> list = kpPointDetailsService.selectKpPointDetailsList(kpPointDetails);
        return getDataTable(list);
    }

    /**
     * 导出点数明细列表
     */
    @PreAuthorize("@ss.hasPermi('kuaipai:point:export')")
    @Log(title = "点数明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KpPointDetails kpPointDetails) {
        List<KpPointDetails> list = kpPointDetailsService.selectKpPointDetailsList(kpPointDetails);
        ExcelUtil<KpPointDetails> util = new ExcelUtil<KpPointDetails>(KpPointDetails.class);
        util.exportExcel(response, list, "点数明细数据");
    }

    /**
     * 获取点数明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('kuaipai:point:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(kpPointDetailsService.selectKpPointDetailsById(id));
    }

    /**
     * 新增点数明细
     */
    @PreAuthorize("@ss.hasPermi('kuaipai:point:add')")
    @Log(title = "点数明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KpPointDetails kpPointDetails) {
        kpPointDetails.setUserName(getUsername());
        kpPointDetails.setUserId(getUserId());
        return toAjax(kpPointDetailsService.insertKpPointDetails(kpPointDetails));
    }

    /**
     * 修改点数明细
     */
    @PreAuthorize("@ss.hasPermi('kuaipai:point:edit')")
    @Log(title = "点数明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KpPointDetails kpPointDetails) {
        kpPointDetails.setUpdater(getUsername());
        kpPointDetails.setUserId(getUserId());
        return toAjax(kpPointDetailsService.updateKpPointDetails(kpPointDetails));
    }

    /**
     * 删除点数明细
     */
    @PreAuthorize("@ss.hasPermi('kuaipai:point:remove')")
    @Log(title = "点数明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(kpPointDetailsService.deleteKpPointDetailsByIds(ids));
    }
}
